package com.mes.device.controller;

import com.mes.common.pojo.MESResult;
import com.mes.device.entity.UpkeepConnectInsert;
import com.mes.device.server.UpkeepServer;
import com.mes.pojo.device.Upkeep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 张喆
 * @Company
 * @Description
 * @Time 2024/10/19 10:11
 */
@RestController
@CrossOrigin
@RequestMapping("/upkeep")
public class UpkeepController {
    @Autowired
    private UpkeepServer upkeepServer;
    @GetMapping("/list")
    public MESResult list(Upkeep upkeep, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer limit){
        return upkeepServer.queryAll(upkeep,pageNum,limit);
    }
    @GetMapping("/getUpdate")
    public MESResult updateInfo(String upkeepId){
        return upkeepServer.queryById(upkeepId);
    }
    @GetMapping("/getDetail")
    public MESResult getDetail(String upkeepId){
        return upkeepServer.queryDesc(upkeepId);
    }
    @DeleteMapping("/deleteDevice")
    public MESResult deleteDevice(String upkeepId,String deviceId){
        return upkeepServer.deleteConnectDevice(upkeepId,deviceId);
    }
    @DeleteMapping("/deleteUpkeepType")
    public MESResult deleteUpkeepType(String upkeepId,String upkeepTypeId){
        return upkeepServer.deleteConnectUpkeepType(upkeepId,upkeepTypeId);
    }
    @DeleteMapping("/delete")
    public MESResult deleteDevice(String upkeepId){
        return upkeepServer.deleteUpkeep(upkeepId);
    }
    @PutMapping("/update")
    public MESResult update(@RequestBody Upkeep upkeep){
        return upkeepServer.updateUpkeep(upkeep);
    }
    @PostMapping("/insert")
    public MESResult insert(@RequestBody Upkeep upkeep){
        return upkeepServer.insertUpkeep(upkeep);
    }
    @PostMapping("/insertDevice")
    public MESResult insertDevice(@RequestBody UpkeepConnectInsert upkeepConnectInsert){
        return upkeepServer.insertConnectDevice(upkeepConnectInsert.getUpkeepId(), upkeepConnectInsert.getDeviceIds());
    }
    @PostMapping("/insertUpkeepType")
    public MESResult insertUpkeepType(@RequestBody UpkeepConnectInsert upkeepConnectInsert){
        return upkeepServer.insertConnectUpkeepType(upkeepConnectInsert.getUpkeepId(), upkeepConnectInsert.getUpkeepTypeIds());
    }
}
